{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 公众号：数据不吹牛，更多案例和有趣分析等你来撩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import re\n",
    "import numpy as np\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "os.chdir('C:\\\\Users\\\\Administrator\\\\教程\\\\interest analyse')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "一共 1794 条评论数据\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>买家</th>\n",
       "      <th>初评内容</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>蓝**e</td>\n",
       "      <td>诚信的卖家，暴力快递碎了一瓶马上补发了，吃完继续，祝老板生意兴隆！</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>自**1</td>\n",
       "      <td>客服态度非常好（我主要是看重售后服务）、物流也棒棒的、李子柒酱超级好吃😋、有了李子柒牛肉酱、...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>浓**浆</td>\n",
       "      <td>爱了，超符合口味，太喜欢了 李子柒我爱你</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>刘**芸</td>\n",
       "      <td>味道很不错！</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>林**3</td>\n",
       "      <td>好吃，不辣，稍贵</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     买家                                               初评内容\n",
       "0  蓝**e                  诚信的卖家，暴力快递碎了一瓶马上补发了，吃完继续，祝老板生意兴隆！\n",
       "1  自**1  客服态度非常好（我主要是看重售后服务）、物流也棒棒的、李子柒酱超级好吃😋、有了李子柒牛肉酱、...\n",
       "2  浓**浆                               爱了，超符合口味，太喜欢了 李子柒我爱你\n",
       "3  刘**芸                                             味道很不错！\n",
       "4  林**3                                           好吃，不辣，稍贵"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel('李子柒辣椒酱评论.xlsx')\n",
    "print('一共 %d 条评论数据' % len(df))\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 把评价分成短句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['诚信的卖家', '暴力快递碎了一瓶马上补发了', '吃完继续', '祝老板生意兴隆', ''],\n",
       " ['客服态度非常好（我主要是看重售后服务）',\n",
       "  '物流也棒棒的',\n",
       "  '李子柒酱超级好吃😋',\n",
       "  '有了李子柒牛肉酱',\n",
       "  '麻麻再也不用担心我吃不饱啦',\n",
       "  ''],\n",
       " ['爱了', '超符合口味', '太喜欢了', '李子柒我爱你'],\n",
       " ['味道很不错', ''],\n",
       " ['好吃', '不辣', '稍贵']]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result = []\n",
    "for i in df['初评内容']:\n",
    "    #根据标点符号来拆分内容\n",
    "    result.append(re.split('[:：,，.。!！~·`\\;； ……、]',i))\n",
    "result[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 以物流为例，做个判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "物流负面倾向\n"
     ]
    }
   ],
   "source": [
    "for word in result[0]:\n",
    "    #先判断是不是物流相关的\n",
    "    if '物流' in word or '快递' in word or '配送' in word or '取货' in word:\n",
    "        #再判断是正面还是负面情感\n",
    "        if '好' in word or '不错' in word or '棒' in word or '满意' in word or '迅速' in word:\n",
    "            print('物流正面倾向')\n",
    "        elif '慢' in word or '龟速' in word or '暴力' in word or '差' in word:\n",
    "            print('物流负面倾向')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实现代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = []\n",
    "    \n",
    "for i in df['初评内容']:\n",
    "    #根据标点符号来拆分内容\n",
    "    result.append(re.split('[:：,，.。!！~·`\\;； ……、]',i))\n",
    "        \n",
    "def judge_comment(df,result):\n",
    "    \n",
    "    judges = pd.DataFrame(np.zeros(13 * len(df)).reshape(len(df),13),\n",
    "                      columns = ['品牌','物流正面','物流负面','包装正面','包装负面','原料正面',\n",
    "                                 '原料负面','口感正面','口感负面','日期正面','日期负面',\n",
    "                                 '性价比正面','性价比负面'])\n",
    "    \n",
    "    for i in range(len(result)):\n",
    "        \n",
    "        words = result[i]\n",
    "        for word in words:\n",
    "            #李子柒的产品具有强IP属性，基本都是正面评价，这里不统计情绪，只统计提及次数\n",
    "            if '李子柒' in word or '子柒' in word or '小柒' in word or '李子七' in word\\\n",
    "                or '小七' in word:\n",
    "                    judges.iloc[i]['品牌'] = 1\n",
    "\n",
    "            #先判断是不是物流相关的\n",
    "            if '物流' in word or '快递' in word or '配送' in word or '取货' in word:\n",
    "                #再判断是正面还是负面情感\n",
    "                if '好' in word or '不错' in word or '棒' in word or '满意' in word or '迅速' in word:\n",
    "                    judges.iloc[i]['物流正面'] = 1\n",
    "                elif '慢' in word or '龟速' in word or '暴力' in word or '差' in word:\n",
    "                    judges.iloc[i]['物流负面'] = 1\n",
    "\n",
    "            #判断是否包装相关\n",
    "            if '包装' in word or '盒子' in word or '袋子' in word or '外观' in word:\n",
    "                if '高端' in word or '大气' in word or '还行' in word or '完整' in word or '好' in word or\\\n",
    "                   '严实' in word or '紧' in word:\n",
    "                    judges.iloc[i]['包装正面'] = 1\n",
    "                elif  '破' in word or '破损' in word or '瘪' in word or '简陋' in word:\n",
    "                    judges.iloc[i]['包装负面'] = 1\n",
    "\n",
    "            #产品\n",
    "            #产品原料是牛肉为主，且评价大多会提到牛肉，因此我们把这个单独拎出来分析\n",
    "            if '肉' in word:\n",
    "                if '大' in word or '多' in word or '足' in word or '香' in word or '才' in word:\n",
    "                    judges.iloc[i]['原料正面'] = 1\n",
    "                elif '小' in word or '少' in word or '没' in word:\n",
    "                    judges.iloc[i]['原料负面'] = 1\n",
    "\n",
    "            #口感的情绪\n",
    "            if '口味' in word or '味道' in word or '口感' in word or '吃起来' in word:\n",
    "                if '不错' in word or '好' in word or '棒' in word or '鲜' in word or\\\n",
    "                    '可以' in word or '喜欢' in word or '符合' in word:\n",
    "                    judges.iloc[i]['口感正面'] = 1\n",
    "                elif '不好' in word or '不行' in word or '不鲜' in word or\\\n",
    "                    '太烂' in word:\n",
    "                    judges.iloc[i]['口感负面'] = 1\n",
    "\n",
    "            #口感方面，有些是不需要出现前置词，消费者直接评价好吃难吃的，例如：\n",
    "            if '难吃' in word or '不好吃' in word:\n",
    "                judges.iloc[i]['口感负面'] = 1\n",
    "            elif '好吃' in word or '香' in word:\n",
    "                judges.iloc[i]['口感正面'] = 1\n",
    "\n",
    "            #日期是不是新鲜\n",
    "            if '日期' in word or '时间' in word or '保质期' in word:\n",
    "                if '新鲜' in word:\n",
    "                    judges.iloc[i]['日期正面'] = 1\n",
    "                elif '久' in word or '长' in word:\n",
    "                    judges.iloc[i]['日期负面'] = 1\n",
    "            elif '过期' in word:\n",
    "                judges.iloc[i]['日期负面'] = 1\n",
    "\n",
    "            #性价比\n",
    "            if '划算' in word or '便宜' in word or '赚了' in word or '囤货' in word or '超值' in word or \\\n",
    "                '太值' in word or '物美价廉' in word or '实惠' in word or '性价比高' in word or '不贵' in word: \n",
    "                judges.iloc[i]['性价比正面'] = 1\n",
    "            elif  '贵' in word or '不值' in word or '亏了' in word or '不划算' in word or '不便宜' in word:\n",
    "                judges.iloc[i]['性价比负面'] = 1\n",
    "                \n",
    "    final_result = pd.concat([df,judges],axis = 1)\n",
    "    \n",
    "    return final_result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 计算之"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "judges = judge_comment(df,result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>买家</th>\n",
       "      <th>初评内容</th>\n",
       "      <th>品牌</th>\n",
       "      <th>物流正面</th>\n",
       "      <th>物流负面</th>\n",
       "      <th>包装正面</th>\n",
       "      <th>包装负面</th>\n",
       "      <th>原料正面</th>\n",
       "      <th>原料负面</th>\n",
       "      <th>口感正面</th>\n",
       "      <th>口感负面</th>\n",
       "      <th>日期正面</th>\n",
       "      <th>日期负面</th>\n",
       "      <th>性价比正面</th>\n",
       "      <th>性价比负面</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>蓝**e</td>\n",
       "      <td>诚信的卖家，暴力快递碎了一瓶马上补发了，吃完继续，祝老板生意兴隆！</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>自**1</td>\n",
       "      <td>客服态度非常好（我主要是看重售后服务）、物流也棒棒的、李子柒酱超级好吃😋、有了李子柒牛肉酱、...</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>浓**浆</td>\n",
       "      <td>爱了，超符合口味，太喜欢了 李子柒我爱你</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     买家                                               初评内容   品牌  物流正面  物流负面  \\\n",
       "0  蓝**e                  诚信的卖家，暴力快递碎了一瓶马上补发了，吃完继续，祝老板生意兴隆！  0.0   0.0   1.0   \n",
       "1  自**1  客服态度非常好（我主要是看重售后服务）、物流也棒棒的、李子柒酱超级好吃😋、有了李子柒牛肉酱、...  1.0   1.0   0.0   \n",
       "2  浓**浆                               爱了，超符合口味，太喜欢了 李子柒我爱你  1.0   0.0   0.0   \n",
       "\n",
       "   包装正面  包装负面  原料正面  原料负面  口感正面  口感负面  日期正面  日期负面  性价比正面  性价比负面  \n",
       "0   0.0   0.0   0.0   0.0   0.0   0.0   0.0   0.0    0.0    0.0  \n",
       "1   0.0   0.0   0.0   0.0   1.0   0.0   0.0   0.0    0.0    0.0  \n",
       "2   0.0   0.0   0.0   0.0   1.0   0.0   0.0   0.0    0.0    0.0  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "judges.describe()\n",
    "judges.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 次数和占比计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>分类</th>\n",
       "      <th>提及次数</th>\n",
       "      <th>占比</th>\n",
       "      <th>高级分类</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>口感正面</td>\n",
       "      <td>1107.0</td>\n",
       "      <td>0.570619</td>\n",
       "      <td>口感</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>原料正面</td>\n",
       "      <td>324.0</td>\n",
       "      <td>0.167010</td>\n",
       "      <td>原料</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>品牌</td>\n",
       "      <td>186.0</td>\n",
       "      <td>0.095876</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>性价比正面</td>\n",
       "      <td>95.0</td>\n",
       "      <td>0.048969</td>\n",
       "      <td>性价比</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>包装正面</td>\n",
       "      <td>68.0</td>\n",
       "      <td>0.035052</td>\n",
       "      <td>包装</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>性价比负面</td>\n",
       "      <td>58.0</td>\n",
       "      <td>0.029897</td>\n",
       "      <td>性价比</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>原料负面</td>\n",
       "      <td>53.0</td>\n",
       "      <td>0.027320</td>\n",
       "      <td>原料</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>口感负面</td>\n",
       "      <td>19.0</td>\n",
       "      <td>0.009794</td>\n",
       "      <td>口感</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>物流正面</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.005155</td>\n",
       "      <td>物流</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>物流负面</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.004639</td>\n",
       "      <td>物流</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>日期正面</td>\n",
       "      <td>7.0</td>\n",
       "      <td>0.003608</td>\n",
       "      <td>日期</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>日期负面</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.002062</td>\n",
       "      <td>日期</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>包装负面</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>包装</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       分类    提及次数        占比 高级分类\n",
       "7    口感正面  1107.0  0.570619   口感\n",
       "5    原料正面   324.0  0.167010   原料\n",
       "0      品牌   186.0  0.095876     \n",
       "11  性价比正面    95.0  0.048969  性价比\n",
       "3    包装正面    68.0  0.035052   包装\n",
       "12  性价比负面    58.0  0.029897  性价比\n",
       "6    原料负面    53.0  0.027320   原料\n",
       "8    口感负面    19.0  0.009794   口感\n",
       "1    物流正面    10.0  0.005155   物流\n",
       "2    物流负面     9.0  0.004639   物流\n",
       "9    日期正面     7.0  0.003608   日期\n",
       "10   日期负面     4.0  0.002062   日期\n",
       "4    包装负面     0.0  0.000000   包装"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rank = judges.iloc[:,2:].sum().reset_index().sort_values(0,ascending = False)\n",
    "rank.columns = ['分类','提及次数']\n",
    "rank['占比'] = rank['提及次数'] / rank['提及次数'].sum()\n",
    "rank['高级分类'] = rank['分类'].str[:-2]\n",
    "rank"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 原料负面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>分类</th>\n",
       "      <th>提及次数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>原料负面</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>口感正面</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>原料正面</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>品牌</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>包装正面</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>性价比正面</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>性价比负面</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       分类 提及次数\n",
       "8    原料负面   53\n",
       "9    口感正面   24\n",
       "7    原料正面    8\n",
       "2      品牌    3\n",
       "5    包装正面    2\n",
       "13  性价比正面    2\n",
       "14  性价比负面    2"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source = judges.loc[judges['原料负面'] == 1,]\n",
    "source_sum = source.sum().reset_index().loc[2:,:].sort_values(0,ascending = False)\n",
    "source_sum.columns = ['分类','提及次数']\n",
    "source_sum.loc[source_sum['提及次数'] > 0,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>买家</th>\n",
       "      <th>初评内容</th>\n",
       "      <th>品牌</th>\n",
       "      <th>物流正面</th>\n",
       "      <th>物流负面</th>\n",
       "      <th>包装正面</th>\n",
       "      <th>包装负面</th>\n",
       "      <th>原料正面</th>\n",
       "      <th>原料负面</th>\n",
       "      <th>口感正面</th>\n",
       "      <th>口感负面</th>\n",
       "      <th>日期正面</th>\n",
       "      <th>日期负面</th>\n",
       "      <th>性价比正面</th>\n",
       "      <th>性价比负面</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>绿**辰</td>\n",
       "      <td>好吃，只是牛肉太少了</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>香**蓉</td>\n",
       "      <td>牛肉酱，味道不错。牛肉比较少，有时候一瓶有很多肥的，很无语的感觉。</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>开**洲</td>\n",
       "      <td>不吹不黑，事实说话，味道还可以，不过说好的牛肉只是很小很小很一小块，牛肉块数量也屈指可数，这...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>凝**贝</td>\n",
       "      <td>肉粒不小，老公喜欢吃</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>冥**天</td>\n",
       "      <td>还好吧，没啥牛肉味</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      买家                                               初评内容   品牌  物流正面  物流负面  \\\n",
       "24  绿**辰                                         好吃，只是牛肉太少了  0.0   0.0   0.0   \n",
       "56  香**蓉                  牛肉酱，味道不错。牛肉比较少，有时候一瓶有很多肥的，很无语的感觉。  0.0   0.0   0.0   \n",
       "74  开**洲  不吹不黑，事实说话，味道还可以，不过说好的牛肉只是很小很小很一小块，牛肉块数量也屈指可数，这...  0.0   0.0   0.0   \n",
       "86  凝**贝                                         肉粒不小，老公喜欢吃  0.0   0.0   0.0   \n",
       "92  冥**天                                          还好吧，没啥牛肉味  0.0   0.0   0.0   \n",
       "\n",
       "    包装正面  包装负面  原料正面  原料负面  口感正面  口感负面  日期正面  日期负面  性价比正面  性价比负面  \n",
       "24   0.0   0.0   0.0   1.0   1.0   0.0   0.0   0.0    0.0    0.0  \n",
       "56   0.0   0.0   0.0   1.0   1.0   0.0   0.0   0.0    0.0    0.0  \n",
       "74   0.0   0.0   0.0   1.0   1.0   0.0   0.0   0.0    0.0    1.0  \n",
       "86   0.0   0.0   0.0   1.0   0.0   0.0   0.0   0.0    0.0    0.0  \n",
       "92   0.0   0.0   0.0   1.0   0.0   0.0   0.0   0.0    0.0    0.0  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "scrolled": false
   },
   "source": [
    "### 性价比负面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>分类</th>\n",
       "      <th>提及次数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>性价比负面</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>口感正面</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>原料正面</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>性价比正面</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>品牌</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>原料负面</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>物流负面</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>包装正面</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       分类 提及次数\n",
       "14  性价比负面   58\n",
       "9    口感正面   44\n",
       "7    原料正面    8\n",
       "13  性价比正面    7\n",
       "2      品牌    3\n",
       "8    原料负面    2\n",
       "4    物流负面    1\n",
       "5    包装正面    1"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price = judges.loc[judges['性价比负面'] == 1,]\n",
    "price_sum = price.sum().reset_index().loc[2:,:].sort_values(0,ascending = False)\n",
    "price_sum.columns = ['分类','提及次数']\n",
    "price_sum.loc[price_sum['提及次数'] > 0,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>买家</th>\n",
       "      <th>初评内容</th>\n",
       "      <th>品牌</th>\n",
       "      <th>物流正面</th>\n",
       "      <th>物流负面</th>\n",
       "      <th>包装正面</th>\n",
       "      <th>包装负面</th>\n",
       "      <th>原料正面</th>\n",
       "      <th>原料负面</th>\n",
       "      <th>口感正面</th>\n",
       "      <th>口感负面</th>\n",
       "      <th>日期正面</th>\n",
       "      <th>日期负面</th>\n",
       "      <th>性价比正面</th>\n",
       "      <th>性价比负面</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>林**3</td>\n",
       "      <td>好吃，不辣，稍贵</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>穆**麦</td>\n",
       "      <td>第一次吃觉得一般，后来吃了其他的牛肉酱之后，发现这个真的非常好吃，但平常价格也是真的有点贵啊...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>霹**袁</td>\n",
       "      <td>味道挺不错，可是太贵了 本来想着59三瓶还行 结果两瓶 不太划算</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>吕**三</td>\n",
       "      <td>很好吃，就是价格太贵了</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>莎**4</td>\n",
       "      <td>感觉还是在直播间买的更划算一点，要是平常买的话太贵了。</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      买家                                               初评内容   品牌  物流正面  物流负面  \\\n",
       "4   林**3                                           好吃，不辣，稍贵  0.0   0.0   0.0   \n",
       "13  穆**麦  第一次吃觉得一般，后来吃了其他的牛肉酱之后，发现这个真的非常好吃，但平常价格也是真的有点贵啊...  0.0   0.0   0.0   \n",
       "31  霹**袁                   味道挺不错，可是太贵了 本来想着59三瓶还行 结果两瓶 不太划算  0.0   0.0   0.0   \n",
       "41  吕**三                                        很好吃，就是价格太贵了  0.0   0.0   0.0   \n",
       "44  莎**4                        感觉还是在直播间买的更划算一点，要是平常买的话太贵了。  0.0   0.0   0.0   \n",
       "\n",
       "    包装正面  包装负面  原料正面  原料负面  口感正面  口感负面  日期正面  日期负面  性价比正面  性价比负面  \n",
       "4    0.0   0.0   0.0   0.0   1.0   0.0   0.0   0.0    0.0    1.0  \n",
       "13   0.0   0.0   0.0   0.0   1.0   0.0   0.0   0.0    0.0    1.0  \n",
       "31   0.0   0.0   0.0   0.0   1.0   0.0   0.0   0.0    1.0    1.0  \n",
       "41   0.0   0.0   0.0   0.0   1.0   0.0   0.0   0.0    0.0    1.0  \n",
       "44   0.0   0.0   0.0   0.0   0.0   0.0   0.0   0.0    1.0    1.0  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 物流负面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>买家</th>\n",
       "      <th>初评内容</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>蓝**e</td>\n",
       "      <td>诚信的卖家，暴力快递碎了一瓶马上补发了，吃完继续，祝老板生意兴隆！</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>314</th>\n",
       "      <td>原**像</td>\n",
       "      <td>一般，除了贵，物流也不是一般差，极差！！！！</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>315</th>\n",
       "      <td>辽**李</td>\n",
       "      <td>物流太慢了</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>319</th>\n",
       "      <td>恋**你</td>\n",
       "      <td>双十一买的，价格很划算，还没吃，不知道味道怎么样，物流挺慢的，很久才收到</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>450</th>\n",
       "      <td>全**7</td>\n",
       "      <td>物流极慢！，二十多天才收到货，无语了！\u0001极差，爱理不理</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>632</th>\n",
       "      <td>妖**吖</td>\n",
       "      <td>快递实在是太慢啦</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790</th>\n",
       "      <td>厌**8</td>\n",
       "      <td>双十一最慢的一个快递</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1693</th>\n",
       "      <td>胡**5</td>\n",
       "      <td>超级好评，味道服务都是非常好的。一共寄了三次来，前面两次因为快递太暴力了，各种漏油，瓶子都摔...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1700</th>\n",
       "      <td>一**郝</td>\n",
       "      <td>牛肉粒很大，不错，味道也很好，货真价实的好，就是邮政快递感觉有点慢，等不及的想品尝这个酱，总...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        买家                                               初评内容\n",
       "0     蓝**e                  诚信的卖家，暴力快递碎了一瓶马上补发了，吃完继续，祝老板生意兴隆！\n",
       "314   原**像                             一般，除了贵，物流也不是一般差，极差！！！！\n",
       "315   辽**李                                              物流太慢了\n",
       "319   恋**你               双十一买的，价格很划算，还没吃，不知道味道怎么样，物流挺慢的，很久才收到\n",
       "450   全**7                        物流极慢！，二十多天才收到货，无语了！\u0001极差，爱理不理\n",
       "632   妖**吖                                           快递实在是太慢啦\n",
       "790   厌**8                                         双十一最慢的一个快递\n",
       "1693  胡**5  超级好评，味道服务都是非常好的。一共寄了三次来，前面两次因为快递太暴力了，各种漏油，瓶子都摔...\n",
       "1700  一**郝  牛肉粒很大，不错，味道也很好，货真价实的好，就是邮政快递感觉有点慢，等不及的想品尝这个酱，总..."
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "judges.loc[judges['物流负面'] == 1,].iloc[:,:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
